<template>
  <div class="app-container">
    <div class="radio-box">
      <el-radio-group
        v-model="queryParams.closeState"
        @change="changeStatus"
        size="small"
      >
        <el-radio-button :label="''">
          <div>提现审核中</div>
        </el-radio-button>
        <el-radio-button :label="'0'">
          <div>提现成功</div>
        </el-radio-button>
        <el-radio-button :label="'1'">
          <div>提现失败</div>
        </el-radio-button>
      </el-radio-group>
    </div>
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      v-show="showSearch"
    >
      <div class="box" v-if="queryParams.closeState == 1">
        <div>已提现金额: 1000元</div>
        <div>未提现: 1000元</div>
      </div>
      <div v-else>
        <el-form-item label=" " prop="name">
          <el-input
            v-model="queryParams.name"
            placeholder="收款人"
            clearable
            size="small"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            icon="el-icon-search"
            size="mini"
            @click="handleQuery"
            >搜索</el-button
          >
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
            >重置</el-button
          >
        </el-form-item>
      </div>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-button type="primary" size="mini" @click="handleAdd">提现</el-button>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="typeList"
      @selection-change="handleSelectionChange"
      ref="multipleTable"
    >
      <el-table-column type="selection" width="55" align="center" />
      <!-- <el-table-column label="序号" align="center" prop="id" width="55">
        <template slot-scope="scope">
          <div>
            {{
              scope.$index +
              (queryParams.pageNum - 1) * queryParams.pageSize +
              1
            }}
          </div>
        </template>
      </el-table-column> -->
      <el-table-column
        label="字典id"
        align="center"
        prop="dictId"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="字典名称"
        align="center"
        prop="dictName"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="提现金额"
        align="center"
        prop="money"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="提现银行卡"
        align="center"
        prop="bankurl"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="提现银行"
        :show-overflow-tooltip="true"
        align="center"
        prop="bank"
      />
      <el-table-column label="提现收款人" align="center" prop="man">
      </el-table-column>
      <el-table-column label="提现时间" align="center" prop="time">
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
        width="200"
        v-if="queryParams.status != '0'"
        fixed="right"
      >
        <template slot-scope="scope">
          <el-button size="mini" type="text" @click="handleApproval(scope.row)"
            >审核</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改公告对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="780px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="180px">
        <el-row>
          <el-col :span="24">
            <el-form-item label="未提现金额" prop="name">
              <el-input
                v-model="form.name"
                placeholder="请输入商品名称"
                style="width: 200px"
              />
            </el-form-item>
            <el-form-item label="请输入您本次提现的金额" prop="noticeType">
              <el-input v-model="form.name" style="width: 200px" />
            </el-form-item>
            <el-form-item label="提现银行" prop="noticeType">
              <el-input v-model="form.name" style="width: 200px" />
            </el-form-item>
            <el-form-item label="提现银行卡号" prop="noticeType">
              <el-input v-model="form.name" style="width: 200px" />
            </el-form-item>
            <el-form-item label="收款人姓名" prop="noticeType">
              <el-input v-model="form.name" style="width: 200px" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">提交请求</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listfinance } from "@/api/finance";
import {
  listType,
  getType,
  delType,
  addType,
  updateType,
  refreshCache,
} from "@/api/system/dict/type";
import Editor from "@/components/Editor";

export default {
  name: "commodity",
  components: {
    Editor,
  },
  data() {
    return {
      // 遮罩层
      loading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 公告表格数据
      typeList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 类型数据字典
      statusOptions: [],
      // 状态数据字典
      typeOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        closeState: "",
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        name: [
          { required: true, message: "商品名称不能为空", trigger: "blur" },
        ],
        noticeType: [
          { required: true, message: "公告类型不能为空", trigger: "change" },
        ],
      },
      type: "0",
      commodityBrandoptions: [],
      selectionarr: [],
    };
  },
  created() {
    this.getList();
    this.getDicts("sys_notice_status").then((response) => {
      this.statusOptions = response.data;
    });
    this.getDicts("sys_notice_type").then((response) => {
      this.typeOptions = response.data;
    });
    this.getDicts("pp").then((response) => {
      this.commodityBrandoptions = response.data;
    });
  },
  methods: {
    handleAdd() {},
    //   去提现
    getWithdraw() {
      this.open = true;
    },
    // 提现记录
    withdrawalRecord() {
      this.reset();
      this.$router.push({
        path: "/commodity/edit",
        query: {
          type: "reject",
          title: "驳回海关商品备案",
          data: row,
        },
      });
    },
    /** 查询公告列表 */
    handelcopy() {
      copycommodity().then((res) => {
        this.msgSuccess("复制成功");
      });
    },
    /** 查询公告列表 */
    changeStatus(value) {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    getcheck() {
      this.$confirm;
    },
    /** 查询公告列表 */
    getList() {
      this.loading = true;
      listType(this.addDateRange(this.queryParams, this.dateRange)).then(
        (response) => {
          this.typeList = response.rows;
          this.changecurrent();
          this.total = response.total;
          this.loading = false;
        }
      );
    },
    // 公告状态字典翻译
    statusFormat(row, column) {
      return this.selectDictLabel(this.statusOptions, row.status);
    },
    // 公告状态字典翻译
    typeFormat(row, column) {
      return this.selectDictLabel(this.typeOptions, row.noticeType);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        noticeTitle: undefined,
        noticeType: undefined,
        noticeContent: undefined,
        status: "0",
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
      selection.map((item, index) => {
        item.page = this.queryParams.pageNum;
      });
      this.selectionarr[this.queryParams.pageNum] = selection;
      // console.log(this.selectionarr);s
    },
    removalselect(selectionarr, current, selection, index) {
      let selectionarrid = [];
      selectionarr.map((item) => {
        selectionarrid.push(item.dictId);
      });
      if (selectionarr.length == 0) {
        if (selectionarrid.indexOf(current.dictId) == -1) {
          selectionarr[index] = current;
        }
      } else {
      }
    },
    changecurrent() {
      let rows = [];
      let selectionarr = this.selectionarr;
      selectionarr.map((item) => {
        rows.push(...item);
      });
      this.$nextTick(() => {
        this.$refs.multipleTable.clearSelection();
        this.typeList.forEach((outerItem) => {
          rows.forEach((item) => {
            if (outerItem.dictId == item.dictId) {
              this.$refs.multipleTable.toggleRowSelection(outerItem, true);
            }
          });
        });
      });
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.$router.push({
        path: "/commodity/edit",
        query: {
          type: "add",
          title: "新增海关商品备案",
        },
      });
    },
    /** 审核按钮操作 */
    handleApproval(row) {
      const ids = row.id || this.ids;
      var obj = {
        id: ids,
        status: 0,
      };
      this.$confirm("是否确认审核该商品?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          return approvalcommodity(obj);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("提交审核成功");
        })
        .catch(() => {});
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      this.$router.push({
        path: "/commodity/edit",
        query: {
          type: "edit",
          title: "修改海关商品备案",
          data: row,
        },
      });
    },
    handleUpdatereject(row) {
      this.reset();
      this.$router.push({
        path: "/commodity/edit",
        query: {
          type: "reject",
          title: "驳回海关商品备案",
          data: row,
        },
      });
    },
    handlemore(row) {
      this.reset();
      this.$router.push({
        path: "/commodity/edit",
        query: {
          type: "detail",
          title: "海关商品备案详情",
          data: row,
        },
      });
    },
    handlecopy(row) {
      this.$confirm("是否确认复制该商品?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          return approvalcommodity(obj);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("复制成功");
        })
        .catch(() => {});
    },
    /** 提交按钮 */
    submitForm: function () {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != undefined) {
            updatecommodity(this.form).then((response) => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addcommodity(this.form).then((response) => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm("是否确认删除该商品?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          return delcommodity(ids);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    getbrand(row) {
      let commodityBrandoptions = this.commodityBrandoptions;
      let Brand = "";
      commodityBrandoptions.map((item) => {
        if (row.commodityBrand == item.dictValue) {
          Brand = item.dictLabel;
        }
      });
      return Brand;
    },
    getorderState(val) {
      let str = "";
      if (val == "1") {
        str = "待付款";
      } else if (val == "2") {
        str = "代发货";
      } else if (val == "3") {
        str = "待收货";
      } else if (val == "4") {
        str = "退换货";
      } else if (val == "5") {
        str = "已完成";
      } else if (val == "6") {
        str = "退换成功";
      } else if (val == "7") {
        str = "已关闭";
      }
      return str;
    },
  },
};
</script>
<style scoped lang="scss">
.radio-box {
  margin-bottom: 10px;
}
.stock {
  text-decoration: underline;
}
.copy {
  color: #999;
  cursor: pointer;
}
.box {
  display: flex;
  div {
    margin-right: 20px;
  }
}
</style>